//package com.kly.chatter.api.application.task;
//
//import com.kly.chatter.api.application.utils.DateWeekUtils;
//import com.kly.chatter.db.dao.ChatterWeekStatusDao;
//import com.kly.chatter.db.entity.ChatterWeekStatusEntity;
//import com.kly.sc.api.application.utils.RpcUtils;
//import com.kly.user.chatterService.ChatterUserService;
//import com.kly.user.dto.UserInfoDto;
//import com.kly.user.dto.chatter.response.ChatterDashboardDto;
//import com.kly.user.service.UserService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.text.ParseException;
//import java.text.SimpleDateFormat;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.List;
//
//@Slf4j
//@Component
//public class WeekStatusTask {
//
//    @Resource
//    private UserService userService;
//
//    @Resource
//    private ChatterUserService chatterUserService;
//
//    @Resource
//    private ChatterWeekStatusDao chatterWeekStatusDao;
//
//    @Scheduled(fixedDelay = 30000)
//    public void execute() throws ParseException {
//        log.info("WeekStatusTask begin");
//        List<UserInfoDto> chatterList = RpcUtils.getResult(userService.getUserByUserType("1"));
//        for (UserInfoDto chatter : chatterList) {
//            Date mondayDate = DateWeekUtils.currentWeekMonday();
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
//            int mondayDateInt = Integer.parseInt(sdf.format(mondayDate));
//            long betweenDays = DateWeekUtils.betweenDays(String.valueOf(mondayDateInt));
//            for (int i = 0; i < betweenDays; i++) {
//                Date date = DateWeekUtils.addDay(mondayDate, i);
//                int dateInt = Integer.parseInt(sdf.format(date));
//                ChatterDashboardDto chatterDashboardDto = RpcUtils.getResult(chatterUserService.getChatterDashboardInfo(dateInt, chatter.getUserCode()));
//                ChatterWeekStatusEntity chatterWeekStatus = new ChatterWeekStatusEntity();
//                chatterWeekStatus.setChatterCode(chatter.getUserCode());
//                if (chatterDashboardDto != null) {
//                    chatterWeekStatus.setOnlineRate(BigDecimal.valueOf(chatterDashboardDto.getOnlineRate()));
//                    chatterWeekStatus.setTimelyRate(BigDecimal.valueOf(chatterDashboardDto.getTimelyResponseRate()));
//                } else {
//                    chatterWeekStatus.setOnlineRate(BigDecimal.valueOf(0));
//                    chatterWeekStatus.setTimelyRate(BigDecimal.valueOf(0));
//                }
//                chatterWeekStatus.setTodayTime(dateInt);
//                int today = i + 1;
//                chatterWeekStatus.setToday(today);
//                ChatterWeekStatusEntity chatterWeekStatusEntity = chatterWeekStatusDao.getWeekStatus(chatter.getUserCode(), today);
//                if (chatterWeekStatusEntity == null) {
//                    chatterWeekStatusDao.insert(chatterWeekStatus);
//                } else {
//                    chatterWeekStatus.setId(chatterWeekStatusEntity.getId());
//                    chatterWeekStatusDao.updateByPrimaryKey(chatterWeekStatus);
//                }
//                log.info("WeekStatusTask end" + chatterWeekStatusEntity);
//            }
//        }
//    }
//
//
//}
